<template>
  <div id="home">
    <div class="common-layout">
      <div>
        <div class="home-container-content"></div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed, inject, onMounted, reactive, ref, watch } from "vue";
import { useStore } from "vuex";
import { asyncgetsetup, asyncgetteam } from "../../api";
import { Storekey } from "../../interface";
import Study from "../../mysql_interface/studycodemodel";

// 码客行
const tenant_id = inject<string | undefined>('tenant_id', undefined);

const data = reactive<Study.Isetup>({ banner: {} });

const store = useStore(Storekey);
const user = computed(() => {
  return store.state.user || {};
});
const teamid = computed(() => {
  return user.value?.teamid;
});
// 默认
const defaultTeamInfo = {
  other: {
    banner: [
      {
        name: "banner01.png",
        url: "https://cdn-hterobot.oss-cn-qingdao.aliyuncs.com/image/saas-banner.png",
      },
    ],
  },
};
const teamInfo = ref<Study.Iteam>(defaultTeamInfo);
// 监听团队切换
watch(
  () => teamid.value,
  (o, n) => {
    if (o !== n) start();
  }
);

// 比赛

onMounted(async () => {
  start();
});

async function start() {
  console.log("home.vue start");

  if (teamid.value) {
    // 获取团队数据
    const teamData = await asyncgetteam({ ID: teamid.value as number });
    // delete teamData.other
    // 合并other
    teamInfo.value = {
      ...teamData,
      other: Object.assign({}, defaultTeamInfo.other, teamData.other),
    };
    store.dispatch("actionactivity", {
      teamid: teamid.value,
      tenant_id,
      _limit: 5,
    });
  }

  const { banner = {} } = await asyncgetsetup();
  data.banner = banner;
  store.dispatch("actionquestion", {
    _limit: 5,
    _order: "ID",
    _sortable: "DESC",
  });
}
</script>

<style scoped>
#home {
  padding: var(--container-margin) 5% 0;
  margin: var(--container-margin) 0rem 0 0rem;
  /* 外边距 */
  --container-margin: 20px;
  --container-header-height: 10vh;
  --container-bg-color: #fff;
}

.home-container-content {
  padding: 0;
}

.flex-jc-space-between {
  display: flex;
  justify-content: space-between;
}

.home-item-list {
  background: rgba(255, 255, 255, 0.5);
  font-size: 14px;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 2px;
}

.home-item-list a {
  display: block;
}

.home-item-list:hover {
  background-color: var(--color-f5);
  color: var(--color-cheng);
}

.my-home-div-line i {
  font-size: 16px;
}

.my-home-div .text {
  padding: 12px 14px;

  pre {
    background: none;
    border: none;
    margin: 0;
    padding: 0;
    font-size: 14px;
    font-family: Microsoft YaHei, Arial;
  }
}

/* 我的题目 */
.my-home-question-input-box {
  height: 80px;
  padding: 14px;
  max-width: 270px;

  input {
    height: 40px;
  }
}

.my-home-question-box {
  height: 80px;
  padding: 4px 14px;
}

.my-home-question {
  display: flex;
  justify-content: space-between;
  padding: 4px 4px 0;
  margin: 2px 4px;
  background: rgba(255, 255, 255, 0.5);
  /* border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 2px; */
}

.my-home-question:hover {
  background-color: var(--color-f5);
  color: var(--color-cheng);
}

/* 查看更多 */
.href {
  text-decoration: none;
  color: var(--color-cheng);
  font-size: 14px;
  font-weight: 400;
}

.jhfontweight {
  height: 44px;
  margin: 12px;
  line-height: 44px;
  margin-bottom: 0px;
  padding-left: 12px;
  padding-right: 12px;
  font-size: 14px;
  overflow: hidden;
}

.jhfontweight span {
  overflow: hidden;
  display: inline-block;
}

/* ojSass home banner*/
.home-banner {
  height: auto !important;
}

.home-banner-item {
  width: 100%;
  height: 100%;
  height: auto !important;
  background: white;
}

.home-banner-img {
  height: auto !important;
  object-fit: contain;
}

.my-home-AC-list-header {
  display: flex;
  justify-content: space-between;
  /* align-items: center;
  flex-wrap: wrap;
  height:auto !important; */
}

.my-home-AC-list {
  padding: 0 14px 14px;
}
</style>

<style>
.my-home-AC-list-header .my-home-AC-form-date-picker {
  max-width: 270px !important;
}

/* 轮播图底部有一部分留白需要处理 */
.home-banner-item .el-image {
  overflow: visible;
  height: auto !important;
}

.home-banner .el-carousel__container {
  min-height: auto;
  height: auto !important;
}
</style>
